import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Menu {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @ApiProperty({ description: '名称' })
  menuName: string;

  @Column()
  @ApiProperty({ description: '菜单键/权限键' })
  menuKey: string;

  @Column({ default: false })
  @ApiProperty({ default: false, description: '是否属于菜单' })
  isMenu: boolean;

  @Column({ default: 0 })
  @ApiProperty({ default: 0, description: '排序' })
  menuOrder: number;

  @Column({ default: true })
  @ApiProperty({ default: true, description: '是否禁用' })
  canUse: boolean;

  @Column({ nullable: true })
  @ApiProperty({ description: '是否缓存菜单' })
  keepAlived?: boolean;

  @Column({ nullable: true })
  @ApiProperty({ description: '组件路径' })
  componentPath?: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '菜单图标' })
  menuIcon?: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '菜单类型' })
  isExpandMenu?: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '菜单图片' })
  menuImg?: string;

  @OneToMany(() => Menu, (menu) => menu.parent)
  @ApiProperty({ description: '父级菜单', type: () => Menu })
  children: Menu[];

  @ManyToOne(() => Menu, (menu) => menu.children)
  @JoinColumn({ name: 'parentId' })
  @ApiProperty({ description: '父级菜单', type: () => Menu })
  parent: Menu;
}
